package com.lmx.repoDomain.tmodel;

import javax.persistence.*;

import com.lmx.common.constants.ICommonConstants;
import io.katharsis.resource.annotations.JsonApiToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;
import com.lmx.repoDomain.tmodel.business.User;//huibati;
import java.util.Set;

/**
 * 用户任务表
 */
@Entity
@Table(name = "ccd_user_task")
@JsonApiResource(type = "userTask")
@Inheritance(strategy = InheritanceType.JOINED)
//@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler"})
public class UserTask extends BaseEntity {
	private String code;
	private Integer effectiveTime;//任务生效时间
	private User user;//对应用户
	private Task task;//对应任务
	private Dicttype status;//任务状态,对应字典：taskApplyStatus
    private Short signstatus;// 签到状态
    private Integer clientSigntime;//客户端签到时间
    private String bindPhone;// 绑定的手机号
//    private Set<Worktime> worktimes;// 工作时间
    private Set<ApplyWorktime> applyWorktimes;// 任务工作时间
    private ImsPool imsPool;//坐席号码
    private String phoneNumber;// 坐席号(操作员)
    private String phonePassword;// 坐席号密码
    private String agentNumber;// 固话号（选线组号码）
    private String agentPassword;// 固话号密码
    private Integer todayCallinCount; // 今日呼入数量
    private Integer todayCalloutCount;// 今日呼出数量
    private Integer nearestSigninTime;// 最近签入时间
    private Integer nearestSignoutTime;// 最近签出时间
    private String verifyFailReason;// 审核失败原因
    private Double brokerage;//当前任务佣金（成单）
    private Short isSettleAccount;//是否已结算
    private Integer createTime;//创建时间
    private Integer updateTime;//更新时间
    private String remark;//备注


    @Column(name = "code")
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Column(name = "effective_time")
    public Integer getEffectiveTime() {
        return effectiveTime;
    }

    public void setEffectiveTime(Integer effectiveTime) {
        this.effectiveTime = effectiveTime;
    }

    @JsonApiToOne
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    @JoinColumn(name = "user_id",foreignKey = @ForeignKey(name = "null"))
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    @JsonApiIncludeByDefault
    @JsonApiToOne
    @Fetch(FetchMode.JOIN)
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    @JoinColumn(name = "task_id",foreignKey = @ForeignKey(name = "null"))
    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    @JsonApiToOne
    @JsonApiIncludeByDefault
    @Fetch(FetchMode.JOIN)
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    @JoinColumn(name = "status_id",foreignKey = @ForeignKey(name = "null"))
    public Dicttype getStatus() {
        return status;
    }

    public void setStatus(Dicttype status) {
        this.status = status;
    }

    @Column(name = "signstatus")
    public Short getSignstatus() {
        return signstatus;
    }

    public void setSignstatus(Short signstatus) {
        if(signstatus == null){
//            signstatus = (short)ICommonConstants.SIGNSTATUS.NOTSIGN.ordinal();
            signstatus = 0;
        }
        this.signstatus = signstatus;
    }

    @Column(name = "client_signtime")
    public Integer getClientSigntime() {
        return clientSigntime;
    }

    public void setClientSigntime(Integer clientSigntime) {
        this.clientSigntime = clientSigntime;
    }

    @Column(name = "bind_phone")
    public String getBindPhone() {
        return bindPhone;
    }

    public void setBindPhone(String bindPhone) {
        this.bindPhone = bindPhone;
    }

/*
    @JsonApiToMany
    @JsonApiIncludeByDefault
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    @JoinTable(name = "ccd_apply_worktime", joinColumns = {
            @JoinColumn(name = "user_task_id", nullable = false, updatable = false,foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
            @JoinColumn(name = "worktime_id", nullable = false, updatable = false,foreignKey = @ForeignKey(name = "null")) })
    @Fetch(FetchMode.JOIN)
    public Set<Worktime> getWorktimes() {
        return worktimes;
    }

    public void setWorktimes(Set<Worktime> worktimes) {
        this.worktimes = worktimes;
    }
*/

    @JsonApiToMany
    @JsonApiIncludeByDefault
    @Fetch(FetchMode.JOIN)
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH,mappedBy = "userTask")
    public Set<ApplyWorktime> getApplyWorktimes() {
        return applyWorktimes;
    }

    public void setApplyWorktimes(Set<ApplyWorktime> applyWorktimes) {
        this.applyWorktimes = applyWorktimes;
    }

    @JsonApiToOne
    @JsonApiIncludeByDefault
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    @JoinColumn(name = "ims_id",foreignKey = @ForeignKey(name = "null"))
    @Fetch(FetchMode.JOIN)
    public ImsPool getImsPool() {
        return imsPool;
    }

    public void setImsPool(ImsPool imsPool) {
        this.imsPool = imsPool;
    }

    @Column(name = "phone_number")
    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Column(name = "phone_password")
    public String getPhonePassword() {
        return phonePassword;
    }

    public void setPhonePassword(String phonePassword) {
        this.phonePassword = phonePassword;
    }

    @Column(name = "agent_number")
    public String getAgentNumber() {
        return agentNumber;
    }

    public void setAgentNumber(String agentNumber) {
        this.agentNumber = agentNumber;
    }

    @Column(name = "agent_password")
    public String getAgentPassword() {
        return agentPassword;
    }

    public void setAgentPassword(String agentPassword) {
        this.agentPassword = agentPassword;
    }

    @Column(name = "today_callin_count")
    public Integer getTodayCallinCount() {
        return todayCallinCount;
    }

    public void setTodayCallinCount(Integer todayCallinCount) {
        this.todayCallinCount = todayCallinCount;
    }

    @Column(name = "today_callout_count")
    public Integer getTodayCalloutCount() {
        return todayCalloutCount;
    }

    public void setTodayCalloutCount(Integer todayCalloutCount) {
        this.todayCalloutCount = todayCalloutCount;
    }

    @Column(name = "nearest_signin_time")
    public Integer getNearestSigninTime() {
        return nearestSigninTime;
    }

    public void setNearestSigninTime(Integer nearestSigninTime) {
        this.nearestSigninTime = nearestSigninTime;
    }

    @Column(name = "nearest_signout_time")
    public Integer getNearestSignoutTime() {
        return nearestSignoutTime;
    }

    public void setNearestSignoutTime(Integer nearestSignoutTime) {
        this.nearestSignoutTime = nearestSignoutTime;
    }

    @Column(name = "verify_fail_reason")
    public String getVerifyFailReason() {
        return verifyFailReason;
    }

    public void setVerifyFailReason(String verifyFailReason) {
        this.verifyFailReason = verifyFailReason;
    }

    @Column(name = "broerage")
    public Double getBrokerage() {
        return brokerage;
    }

    public void setBrokerage(Double brokerage) {
        this.brokerage = brokerage;
    }

    @Column(name = "is_settle_account")
    public Short getIsSettleAccount() {
        return isSettleAccount;
    }

    public void setIsSettleAccount(Short isSettleAccount) {
        this.isSettleAccount = isSettleAccount;
    }

    @Column(name = "create_time")
    public Integer getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Integer createTime) {
        this.createTime = createTime;
    }

    @Column(name = "update_time")
    public Integer getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Integer updateTime) {
        this.updateTime = updateTime;
    }

    @Column(name = "remark")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}